package cn.edu.scau.cmi.luochenghao.chapter07;

interface DogState {
	public void showState();
}

class SoftlyState implements DogState {
	public void showState() {
		System.out.println("安静不动，趴在地上");
	}
}

class MeetEnemyState implements DogState {
	public void showState() {
		System.out.println("遇到敌人狂叫，并冲向去狠咬敌人");
	}
}

class MeetFriendState implements DogState {
	public void showState() {
		System.out.println("遇到朋友，摇尾巴");
	}
}

class Dog {
	DogState state;
	public void cry() {
		state.showState();
	}
	public void setState(DogState s) {
		state=s;
	}
}

class MeetAnotherDog implements DogState {
	public void showState() {
		System.out.println("嬉戏");
	}
}

public class E {

	public static void main(String[] args) {
		Dog yellowDog=new Dog();
		yellowDog.setState(new SoftlyState());
		yellowDog.cry();
		yellowDog.setState(new MeetEnemyState());
		yellowDog.cry();
		yellowDog.setState(new MeetFriendState());
		yellowDog.cry();
		yellowDog.setState(new MeetAnotherDog());
		yellowDog.cry();
	}

}
